package com.crm.service.impl.opportunityManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customMapper.opportunityManagerCustomMapper.OpportunityDynamicCustomMapper;
import com.crm.dao.mapper.opportunityManager.OpportunityDynamicMapper;
import com.crm.model.entity.opportunityManager.OpportunityDynamic;
import com.crm.model.entity.opportunityManager.OpportunityDynamicExample;
import com.crm.model.vo.opportunityManager.OpportunityDynamicVO;
import com.crm.service.opportunityManager.OpportunityDynamicDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商机动态
 */
@Service
public class OpportunityDynamicDbServiceImpl implements OpportunityDynamicDbService {

    @Autowired
    private OpportunityDynamicMapper opportunityDynamicMapper;

    @Autowired
    private OpportunityDynamicCustomMapper opportunityDynamicCustomMapper;

    /**
     * 商机管理-新增商机动态
     * @param opportunityDynamic 商机动态实体
     * @return
     */
    @Override
    public Boolean addOpportunityDynamic(OpportunityDynamic opportunityDynamic) {
        Boolean result = false;
        int num = opportunityDynamicMapper.insertSelective(opportunityDynamic);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 查询商机状态是否存在
     * @param opportunityId 商机id
     * @return
     */
    @Override
    public List<OpportunityDynamic> selectByOpportunityId(String opportunityId,Integer operationMode) {
        OpportunityDynamicExample opportunityDynamicExample = new OpportunityDynamicExample();
        OpportunityDynamicExample.Criteria criteria = opportunityDynamicExample.createCriteria();
        criteria.andOperationModeEqualTo(operationMode);
        criteria.andOpportunityIdEqualTo(opportunityId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<OpportunityDynamic> list = opportunityDynamicMapper.selectByExample(opportunityDynamicExample);
        return list;
    }

    /**
     * 修改商机动态
     * @param opportunityDynamic 商机动态实体
     * @return
     */
    @Override
    public Boolean updateOpportunityDynamic(OpportunityDynamic opportunityDynamic) {
        Boolean result = false;
        int num = opportunityDynamicMapper.updateByPrimaryKeySelective(opportunityDynamic);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 商机-商机详情-查询当前商机动态
     * @param opportunityId 商机id
     * @return
     */
    @Override
    public List<OpportunityDynamicVO> opportunityDynamicList(String opportunityId,String opportunityDynamicId) {
        List<OpportunityDynamicVO> list = opportunityDynamicCustomMapper.opportunityDynamicList(opportunityId,opportunityDynamicId);
        return list;
    }
}
